package org.bao.bestmatch.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Configurer {
	private static Configurer instance = null;
	private static final String CFG_FILE_PATH_DEFAULT = "./sys.cfg";
	
	public static String CONFIG_PRO_DATACHECKER = "data_checker_enable";
	/*
	public static String CONFIG_PRO_TFT_FILE_PATH = "tft_data_file";
	public static String CONFIG_PRO_CF_FILE_PATH = "cf_data_file";
	*/
	
	private boolean DATA_CHECKER_ENABLE = false;
	//private String TFT_DATA_FILE = null;
	//private String CF_DATA_FILE = null;
	
	
	public static Configurer getInstance(){
		if(instance == null){
			instance = new Configurer();
		}
		
		Properties pro = new Properties();
		try {
			File file = new File(Configurer.CFG_FILE_PATH_DEFAULT);
			
			//if NO conf. file available,generate automatically
			if(!file.exists()){
				Writer.out(Configurer.CFG_FILE_PATH_DEFAULT,
						"#This is a configuration file generated automatically for BestMatch.\n" +
						"#DO NOT make any change if you are not familiar with this system.\n\n" +
						"#enable DataChecher module,true|false ONLY \n" +
						"data_checker_enable=true\n\n" );
			}
			
			
			pro.load(new FileInputStream(Configurer.CFG_FILE_PATH_DEFAULT));
			
			instance.DATA_CHECKER_ENABLE = Boolean.parseBoolean(pro.getProperty(Configurer.CONFIG_PRO_DATACHECKER));
			//instance.TFT_DATA_FILE = pro.getProperty(Configurer.CONFIG_PRO_TFT_FILE_PATH);
			//instance.CF_DATA_FILE = pro.getProperty(Configurer.CONFIG_PRO_CF_FILE_PATH);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return instance;
	}
	
	public boolean getDataCheckerEnableStatus(){
		return instance.DATA_CHECKER_ENABLE;
	}
	
	/*
	public String getTFTPath(){
		return instance.TFT_DATA_FILE;
	}
	
	public String getCFPath(){
		return instance.CF_DATA_FILE;
	}
	*/
}
